package game.components;

import game.ball.SoccerBall;
import game.scene.MatchScene;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;

public class Camera extends GameComponent<MatchScene> {
	
	private int width;
	private int height;
	private SoccerBall soccerBall;

	public Camera(int width, int height) {
		this.setWidth(width);
		this.setHeight(height);
	}
	
	public void onSceneActivated() {
		this.setSoccerBall(this.getScene().getSoccerBall());
	}
	
	public void update(DeltaState deltaState) {
		if (this.getSoccerBall().isWithinField()) {
			this.setX(this.getSoccerBall().getX() - this.getWidth() / 2);
			this.setY(this.getSoccerBall().getY() - this.getHeight() / 2);
		}
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public SoccerBall getSoccerBall() {
		return soccerBall;
	}

	public void setSoccerBall(SoccerBall soccerBall) {
		this.soccerBall = soccerBall;
	}
}